package com.orhonit.ipb.portal.rest;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.orhonit.ipb.portal.biz.JoThoughtReportBiz;
import com.orhonit.ipb.portal.biz.TbPartyOrgBaseInfoBiz;
import com.orhonit.ipb.portal.entity.JoThoughtReport;
import com.orhonit.ipb.portal.entity.TbPartyOrgBaseInfo;
import com.orhonit.ipb.security.auth.client.annotation.CheckClientToken;
import com.orhonit.ipb.security.auth.client.annotation.CheckUserToken;
import com.orhonit.ipb.security.common.rest.BaseController;
import com.orhonit.ipb.security.common.util.UUIDUtils;

@RestController
@RequestMapping("joThoughtReport")
//@CheckClientToken
//@CheckUserToken
public class JoThoughtReportController extends BaseController<JoThoughtReportBiz,JoThoughtReport> {
	 @Autowired
	private TbPartyOrgBaseInfoBiz tbPartyOrgBaseInfoBiz;
	@Autowired
	private JoThoughtReportBiz joThoughtReportBiz;
	/**
	 * 通过申请id及   type:( 0:积极分子：1发展对象；2：预备党员；3：党员)
	 * @param applyId
	 * @param type
	 * @return
	 */
	@RequestMapping(value = "/getJoThoughtReportList", method = RequestMethod.GET)
	public ResponseEntity<?> getJoThoughtReport1(String applyId){
		Map<String, Object> map=new HashMap<String, Object>(); 
		map.put("applyId", applyId);
		List<JoThoughtReport> joThoughtReport=joThoughtReportBiz.getJoThoughtReportByMap(map);
		return ResponseEntity.ok().body(joThoughtReport);
	}
	/**
	 * 更新思想汇报 
	 * @param data 实体类 JoThoughtReport    json
	 * @return
	 */
	@RequestMapping(value = "/updateJoThoughtReport", method = RequestMethod.POST)
	public ResponseEntity<?> updateJoThoughtReport(String data){
		Gson gson = new Gson();
		JoThoughtReport joThoughtReport = gson.fromJson(data, new TypeToken<JoThoughtReport>() {
		}.getType());
		joThoughtReport.setCreateTime(new Date());
		if(StringUtils.isNotBlank(joThoughtReport.getId())){
			joThoughtReportBiz.updateById(joThoughtReport);
		}
		else{
			joThoughtReport.setId(UUIDUtils.generateUuid());
			joThoughtReportBiz.insertSelective(joThoughtReport);
		}
		
		return ResponseEntity.ok().body("");
	}
	/**
	 * 通过思想回报id查询具体内容
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/getJoThoughtReport", method = RequestMethod.GET)
	public ResponseEntity<?> getJoThoughtReport(String id){
		JoThoughtReport joThoughtReport=joThoughtReportBiz.selectById(id);
		return ResponseEntity.ok().body(joThoughtReport);
	}
	
}